/*******************************************************************************
 * The MOSES project, model based software engineering of networked embedded systems.
 * 
 * Copyright (C) 2010-2013, University of Applied Sciences Wildau,
 * Telematics Research Group, http://www.tm.th-wildau.de/research-group
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Contributors:
 *     University of Applied Sciences Wildau - initial API and implementation
 * 
 * If you are interested in a commercial license please contact us via 
 * e-mail: ralf.vandenhouten@th-wildau.de.
 ******************************************************************************/
/*
* generated by Xtext
*/
package de.thwildau.tm.moses.abnf.ui.labeling;

import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider;

import com.google.inject.Inject;

import de.thwildau.tm.moses.abnf.abnf.NumVal;
import de.thwildau.tm.moses.sdk.labeling.ILabelProviderDelegator;

/**
 * Provides labels for a EObjects.
 * 
 * see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#labelProvider
 */
public class AbnfLabelProvider extends DefaultEObjectLabelProvider {
    
    @Inject
    private ILabelProviderDelegator labelProviderDelegator;

	@Inject
	public AbnfLabelProvider(AdapterFactoryLabelProvider delegate) {
		super(delegate);
	}
    
    @Override
    protected Object doGetText(Object element) {
        if(element instanceof NumVal)
            return getText((NumVal) element);
        return labelProviderDelegator.doGetText(element);
    }
    
    private String getText(NumVal numVal) {
        StringBuilder buf = new StringBuilder();
        buf.append(numVal.eClass().getName());
        buf.append(" (");
        for(int i=0; i<numVal.getValue().size(); i++) {
            if(i > 0)
                buf.append(".");
            buf.append(numVal.getValue().get(i));
        }
        buf.append(" - ");
        buf.append(numVal.getMaxValue());
        buf.append(")");
        return buf.toString();
    }

/*
	//Labels and icons can be computed like this:
	
	String text(MyModel ele) {
	  return "my "+ele.getName();
	}
	 
    String image(MyModel ele) {
      return "MyModel.gif";
    }
*/
}
